<?php

	
	// 执行sql，并将结果以json格式字符串返回
	function query_sql($sql, $conn){
		if(!$rs = $conn->query($sql)){return ($sql);}
		$result = array();
		foreach ($rs->FetchAll(PDO::FETCH_OBJ) as $value) {
			array_push($result, $value);
		}
		return json_encode($result);
	}

	// 向指定文件中写入一行
	function writefile($filename, $content){
		$fp = fopen($filename, 'a');
		fwrite($fp, $content);
		fclose($fp);
	}

	// 写入log日志
	function setLog($content){
		$curTime = date(time(), "Y-m-d h:i:s");
		writefile(__DIR__ . "../../log/logdata.txt", ">>" . $curTime . "|" . $content);
	}



?>